﻿using University.Workshop.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.DataAccess;
using System.Collections.ObjectModel;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for ClientTest and is intended
    ///to contain all ClientTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ClientTest
    {
        PokerServer server = new PokerServer();

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for RegisterNewUser
        ///</summary>
        [TestMethod()]
        public void RegisterNewUserTest()
        {
            server.InitializeServer(3000);
            Client target = new Client(); // TODO: Initialize to an appropriate value
            string username = "Gloria"; // TODO: Initialize to an appropriate value
            string password = "Paramahansa6".GetHashCode().ToString(); // TODO: Initialize to an appropriate value
            string mail = "gloria@gmail.com"; // TODO: Initialize to an appropriate value
            string question = "1"; // TODO: Initialize to an appropriate value
            string answer = "aurora".GetHashCode().ToString(); // TODO: Initialize to an appropriate value
            int size = 1; // TODO: Initialize to an appropriate value
            byte[] picture = new byte[1]; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.RegisterNewUser(username, password, mail, question, answer, size);
            Assert.AreEqual(expected, actual);
            server.DisconnectServer();
         }

        /// <summary>
        ///A test for ChangePassword
        ///</summary>
        [TestMethod()]
        public void ChangePasswordTest()
        {
            server.InitializeServer(3000);
            Client target = new Client(); // TODO: Initialize to an appropriate value
            string userName = "Gloria"; // TODO: Initialize to an appropriate value
            string newPassword = "Paramahansa5".GetHashCode().ToString() ; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.ChangePassword(userName, newPassword);
            Assert.AreEqual(expected, actual);
            server.DisconnectServer();
        }

       

        /// <summary>
        ///A test for GetUsersContacts
        ///</summary>
        [TestMethod()]
        public void GetUsersContactsTest()
        {
            server.InitializeServer(3000);
            Client target = new Client(); // TODO: Initialize to an appropriate value
            //string user = string.Empty; // TODO: Initialize to an appropriate value
            Collection<UserContacts> expected = null;// TODO: Initialize to an appropriate value
            
            Collection<UserContacts> actual;
            actual = target.GetUsersContacts("Luis");
            Assert.AreNotEqual(expected, actual);
            server.DisconnectServer();
        }

        /// <summary>
        ///A test for ChangeStatus
        ///</summary>
        [TestMethod()]
        public void ChangeStatusTest()
        {
            server.InitializeServer(3000);
            Client target = new Client(); // TODO: Initialize to an appropriate value
            string userName = "Luchito"; // TODO: Initialize to an appropriate value
            string userRequest = "Roberto"; // TODO: Initialize to an appropriate value
            string status = "Friends"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.ChangeStatus(userName, userRequest, status);
            Assert.AreEqual(expected, actual);
            server.DisconnectServer();
        }

        /// <summary>
        ///A test for ChangePassword
        ///</summary>
        [TestMethod()]
        public void ChangePasswordTest1()
        {
            server.InitializeServer(3000);
            Client target = new Client(); // TODO: Initialize to an appropriate value
            string userName = "Roberto"; // TODO: Initialize to an appropriate value
            string newPassword = Convert.ToString(("aurora1".GetHashCode())); // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.ChangePassword(userName, newPassword);
            Assert.AreEqual(expected, actual);
            server.DisconnectServer();
        }

        /// <summary>
        ///A test for SendRequest
        ///</summary>
       [TestMethod()]
        public void SendRequestTest()
        {
            server.InitializeServer(3000);
            Client target = new Client(); // TODO: Initialize to an appropriate value
            string userName = "Roberto"; // TODO: Initialize to an appropriate value
            string userRequest = "Baneado"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.SendRequest(userName, userRequest);
            Assert.AreEqual(expected, actual);
           server.DisconnectServer();
        }


       /// <summary>
       ///A test for GetGameStatus
       ///</summary>
       [TestMethod()]
       public void GetGameStatusTest()
       {
           server.InitializeServer(3000);
           Client target = new Client(); // TODO: Initialize to an appropriate value
           User user = new User() ; // TODO: Initialize to an appropriate value
           user.Name = "Gloria";
           user.Chips = 20000;
           string game = "Wheel"; // TODO: Initialize to an appropriate value
           bool expected = true; // TODO: Initialize to an appropriate value
           bool actual;
           actual = target.GetGameStatus(user, game);
           Assert.AreEqual(expected, actual);
           server.DisconnectServer();
       }

       /// <summary>
       ///Una prueba de RegisterNewUser
       ///</summary>
       [TestMethod()]
       public void RegisterNewUserTest1()
       {
           server.InitializeServer(3000);
           Client target = new Client(); // TODO: Inicializar en un valor adecuado
           string userName = "Javier"; // TODO: Inicializar en un valor adecuado
           string password = Convert.ToString("aurora1".GetHashCode());// TODO: Inicializar en un valor adecuado
           string mail = "javi@hotmail.com"; // TODO: Inicializar en un valor adecuado
           string question = "1"; // TODO: Inicializar en un valor adecuado
           string answer = Convert.ToString("aurora".GetHashCode()); // TODO: Inicializar en un valor adecuado
           int size = 1; // TODO: Inicializar en un valor adecuado
           bool expected = true; // TODO: Inicializar en un valor adecuado
           bool actual;
           actual = target.RegisterNewUser(userName, password, mail, question, answer, size);
           Assert.AreEqual(expected, actual);
           server.DisconnectServer();
       }

       /// <summary>
       ///A test for GetQuestionAnswer
       ///</summary>
       [TestMethod()]
       public void GetQuestionAnswerTest()
       {
           server.InitializeServer(3000);

           Client target = new Client(); // TODO: Initialize to an appropriate value
           string userName = "Roberto"; // TODO: Initialize to an appropriate value
           string[] expected = {Convert.ToString("aurora".GetHashCode()),"1"}; // TODO: Initialize to an appropriate value
           string[] actual;
           actual = target.GetQuestionAnswer(userName);
           Assert.AreEqual(expected[0], actual[0]);
           Assert.AreEqual(expected[1],actual[1]);
           server.DisconnectServer();
       }


       /// <summary>
       ///A test for GetAllLevels
       ///</summary>
       [TestMethod()]
       public void GetAllLevelsTest()
       {
           PokerServer pokerServer = new PokerServer();
           pokerServer.InitializeServer(3000);
           LevelDatabase level2 = new LevelDatabase();
           LevelDatabase level3 = new LevelDatabase();
           LevelDatabase level4 = new LevelDatabase();
           LevelDatabase level5 = new LevelDatabase();
           LevelDatabase level6 = new LevelDatabase();

           level2.Chips = 30000;
           level3.Chips = 40000;
           level4.Chips = 60000;
           level5.Chips = 80000;
           level6.Chips = 120000;
           level2.Level = 2;
           level3.Level = 3;
           level4.Level = 4;
           level5.Level = 5;
           level6.Level = 6;
           level2.TimeWon = 10;
           level3.TimeWon = 22;
           level4.TimeWon = 35;
           level5.TimeWon = 60;
           level6.TimeWon = 100;
           Collection<LevelDatabase> expected = new Collection<LevelDatabase>();
           expected.Add(level2);
           expected.Add(level3);
           expected.Add(level4);
           expected.Add(level5);
           expected.Add(level6);
           Client target = new Client(); // TODO: Initialize to an appropriate value
           
           Collection<LevelDatabase> actual;
           actual = target.GetAllLevels;
           Assert.AreEqual(actual.Count,expected.Count);
           pokerServer.DisconnectServer();
       }
    }
}
